package cmarter.dev.entities;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cmarter.dev.chpt2.Utils;


public class Main {

	public static void main(String[] args) {
		List<Apple> apples = Arrays.asList(new Apple("green", 90d, "Granny Smith"),
				   new Apple("green", 150d, "Granny Smith"),
				   new Apple("green", 190d, "smith"),
				   new Apple("green", 149d, "smith"),
				   new Apple("green", 160d, "smith"),
				   new Apple("red", 190d, "Fuji"));	
		
		List<Apple> greenApples = filterApples(apples, Main::isGreen);
		
		Utils.printList(greenApples);

	}
	
	public static boolean isGreen(Apple a) {
		return "green".equalsIgnoreCase(a.getColor());
	}
	public static boolean isHeavy(Apple a) {
		return a.getWeight() >= 150d;
	}	
	public interface Function<T> {
		public boolean test(T t);
	}
	
	public static List<Apple> filterApples(List<Apple> apples, Function<Apple> p) {
		List<Apple> result = new ArrayList<>();
		for (Apple a : apples) {
			if (p.test(a)) {
				result.add(a);
			}
		}
		return result;
	}
}
